package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-07-29
 * Time: 9:01
 */

public class TestDemo {



    //synchronized修饰静态方法
    public synchronized static void method1(){
        synchronized(TestDemo.class){
            //对TestDemo这个类加锁 --->全局的
        }
    }

    //对普通方法加锁
    public synchronized void method2(){

        synchronized(this){
            //对当前对象加锁--->每个对象都对应一把锁
        }

    }


    public static void main(String[] args) {

    }

}
